using System;
using MySql.Data.MySqlClient;

namespace PConexionMySql
{
	/// <summary>
	/// Clase que establece una conexión con una base de datos de MySql
	/// </summary>
	public static class MySqlConnetionHelper
	{
		private static string user;
		private static string pass;
		private static string host;
		private static string dataBank;
		private static MySqlConnection conexion;
		
		static MySqlConnetionHelper()
		{
			user = "root";
			pass = "sistemas";
			host = "localhost";
			dataBank = "dbprueba";			
		}
		
		public static MySqlConnection Connection()
		{
			string conString = "server="+host+"; user="+user+"; password="+pass+"; database="+dataBank+";";
			conexion = new MySqlConnection(conString);
			/*
			try
			{
				conexion = new MySqlConnection(conString);
				conexion.Open();
				Console.WriteLine("Conexión establecida");
			}
			catch(Exception e)
			{
				Console.WriteLine("Error: "+e.Message);
			}
			*/
			return conexion;
		}
		public static void OpenConexion()
		{
			conexion.Open();
		}
		public static void CloseConexion()
		{
			conexion.Close();
		}
	}
}

